﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.Serialization;
using System.Security.Permissions;
using System.Text;

namespace MedReg.Classes
{
    [Serializable]
    public class Qualification : ISerializable
    {
        private QualificationCategory categoryField;

        private Speciality specialityField;

        private decimal yearField;

        private Employee employeeField;

        private static readonly Qualification theOneObject = new Qualification();

        public static Qualification GetQualification()
        {
            return theOneObject;
        }
        /// <remarks/>
        public QualificationCategory Category
        {
            get
            {
                return this.categoryField;
            }
            set
            {
                this.categoryField = value;
            }
        }

        /// <remarks/>
        public Speciality Speciality
        {
            get
            {
                return this.specialityField;
            }
            set
            {
                this.specialityField = value;
            }
        }

        /// <remarks/>
        public decimal Year
        {
            get
            {
                return this.yearField;
            }
            set
            {
                this.yearField = value;
            }
        }

        public Employee Employee
        {
            get
            {
                return employeeField;
            }
            set
            {
                employeeField = value;
            }
        }
         [SecurityPermission(SecurityAction.LinkDemand, Flags = SecurityPermissionFlag.SerializationFormatter)]
        public void GetObjectData(SerializationInfo info, StreamingContext context)
        {
            //throw new NotImplementedException();
            info.AddValue("Category", categoryField);
            info.AddValue("SertificateSpeciality", specialityField);
            info.AddValue("Year", yearField);
        }
        public Qualification()
        {
        }

        public List<Classes.Qualification> getQualificationList(Classes.ArrayOfEmployee sEmployee)
        {

            foreach (var emp in sEmployee)
            {
                foreach (var qualification in emp.EmployeeQualification)
                {
                    qualification.Employee = emp;
                }
            }

            //var awd = sEmployee
            //    .SelectMany(award => award.EmployeeAwards, (Employees, Awards) => new { Employees, Awards })
            //    .Select(AwardsEx => new { Employee = AwardsEx.Employees, AwardsEx.Awards }).ToList();

            var cr = sEmployee.SelectMany(em => em.EmployeeQualification).ToList();

            return cr;
        }
        
    }
}
